/**
 * @Author: jichang
 * @Date: 2024/10/29 17:52:07
 * @LastEditors: jichang
 * @LastEditTime: 2024/10/29 17:52:07
 * Description: 原子指针
 */
#include <atomic>
#include <iostream>
#include <assert.h>

class Foo { };

void test() {
    Foo some_arry[5];

    std::atomic<Foo*> p(some_arry); // 指向第1个元素
    Foo* x = p.fetch_add(2); // +2返回原始值

    if (x == some_arry) {
        std::cout << "x == some_arry\n";
    }
    if (p.load() == &some_arry[2]) {
        std::cout << "p.load() == &some_arry[2]\n";
    }

    x = (p -= 1);

    if (x == &some_arry[1]) {
        std::cout << "x == &some_arry[1]\n";
    }
    if (p.load() == &some_arry[1]) {
        std::cout << "p.load() == &some_arry[1]\n";
    }
}

int main(int argc, char const *argv[])
{
    test();
    
    return 0;
}
